package com.zzptc.zzsgz.bdsjws.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.utils.DanceWageTimer;
import com.zzptc.zzsgz.bdsjws.views.RatingBar;
import com.zzptc.zzsgz.bdsjws.views.RatingView;

import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.rating_view)
    RatingView ratingView;
    int one = new Random().nextInt(10) + 1;
    int two = new Random().nextInt(10) + 1;
    int three = new Random().nextInt(10) + 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //发送
        Intent intent=new Intent();
        intent.setAction("updateVersion");
        sendBroadcast(intent);
        initData();
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
//根据产生的随机数来定（>=8）高 (<=5)低 (8>x>5)中 三元运算符 表达式 结果一； 结果二
        ratingView.addRatingBar(new RatingBar(one, one>8?"清晰度高":(one<=5?"清晰度低":"清晰度中")));
        ratingView.addRatingBar(new RatingBar(two, two>8?"流畅度高":(two<=5?"流畅度低":"流畅度中")));
        ratingView.addRatingBar(new RatingBar(three, three>8?"安全度高":(three<=5?"安全度低":"安全度中")));
        ratingView.show();
        //int num=(int)((one*0.5+two*0.3+three*0.2)*10);

        //监听
        ratingView.setAnimatorListener(new RatingView.AnimatorListener() {
            @Override
            public void onRotateStart() {

            }

            @Override
            public void onRotateEnd() {
                //跳数效果
                int num = (int) ((one * 0.5 + two * 0.3 + three * 0.2) * 10);
                long totalExcureTime = DanceWageTimer.getTotalExecuteTime(num, 20);
                DanceWageTimer danceWageTimer = new DanceWageTimer(totalExcureTime, 20, tvNum, num);
                danceWageTimer.start();
            }

            @Override
            public void onRatingStart() {

            }

            @Override
            public void onRatingEnd() {

            }
        });
    }

    @OnClick(R.id.iv1)
    public void onViewClicked(View view) {
        //Toast.makeText(this, "-------", Toast.LENGTH_SHORT).show();
        startActivities(new Intent[]{new Intent(this, UserActivity.class)});
    }
    @OnClick(R.id.tv_box)
    public void onViewClicked(){
        startActivity(new Intent(this,BBXActivity.class));
    }
}
